package com.ztf.employee.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**import org.apache.shiro.authz.annotation.RequiresPermissions;**/
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ztf.employee.entity.EmployeeEntity;
import com.ztf.employee.service.EmployeeService;
import com.ztf.common.utils.PageUtils;
import com.ztf.common.utils.R;



/**
 * 
 *
 * @author ztf
 * @email ztf@gmail.com
 * @date 2020-04-16 20:12:02
 */
@RefreshScope//配置中心数据自动刷新
@RestController
@RequestMapping("employee/employee")
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;
    @Value("${test.user.name}")
    private String name;
    @Value("${test.user.age}")
    private int age;
    /*测试配置中心*/
    @RequestMapping("/test_conf")
    public R test_conf(){
        return R.ok().put("name",name).put("age",age);
    }
    /*测试远程调用*/
    @RequestMapping("/fequery")
    public R fequery(){
        List<EmployeeEntity> list = employeeService.list();
        return R.ok().put("emp",list);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("employee:employee:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = employeeService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{employeeId}")
    //@RequiresPermissions("employee:employee:info")
    public R info(@PathVariable("employeeId") Integer employeeId){
		EmployeeEntity employee = employeeService.getById(employeeId);

        return R.ok().put("employee", employee);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("employee:employee:save")
    public R save(@RequestBody EmployeeEntity employee){
		employeeService.save(employee);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("employee:employee:update")
    public R update(@RequestBody EmployeeEntity employee){
		employeeService.updateById(employee);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("employee:employee:delete")
    public R delete(@RequestBody Integer[] employeeIds){
		employeeService.removeByIds(Arrays.asList(employeeIds));

        return R.ok();
    }

}
